package com.is2.patchinglife.manager;

import com.is2.patchinglife.R;
import com.is2.patchinglife.activity.TrophyActivity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

/** Utility to create and show notification in the status bar **/

public class NotificationHandler{
	
	static String notif_msg = "got new trophy";
	
	private NotificationHandler(){}
	
	/** Show a notification in the status bar **/
	public static void displayNotificationMessage(String _title, String _text, int _id){
		Context aRef = LocalDataManager.getContext();
		//create the intent to open when the notification is clicked
    	Intent intent = new Intent(aRef, TrophyActivity.class);
    	PendingIntent pIntent = PendingIntent.getActivity(aRef, 0, intent, 0);
    	
    	// get notification time
    	long when = System.currentTimeMillis();
    	
    	// create the notification Object and set some properties.
    	Notification notification = new Notification(R.drawable.notification,notif_msg, when);
		notification.flags = Notification.FLAG_AUTO_CANCEL;			//notification is deleted when clicked
    	notification.sound = Uri.parse("android.resource://com.is2.patchinglife/raw/got_sound_plus");
    	notification.setLatestEventInfo(aRef, _title, _text, pIntent);
    	
    	// get Notification_Service & show notification
    	NotificationManager notificationManager = (NotificationManager) aRef.getSystemService(Context.NOTIFICATION_SERVICE);
	  	notificationManager.notify(_id, notification);
    	
	  	
	  	// NOTIFICATION ALGORITHM BASED ON API VERSION NUMBER
    	/*if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB){
			Notification noti = new Notification.Builder(aRef)
	        .setContentTitle(_title)
	        .setContentText(_text)
	        .setSmallIcon(R.drawable.icon)
	        .setContentIntent(pIntent)
	        .addAction(R.drawable.icon, "Call", pIntent)  	// action for each button (max 3 actions)
	        .addAction(R.drawable.icon, "More", pIntent)
	        .addAction(R.drawable.icon, "And more", pIntent).build();
		    noti.flags |= Notification.FLAG_AUTO_CANCEL;	// hide notification after selection
		    notificationManager.notify(0, noti);
    	
    	}else{
    	  	@SuppressWarnings("deprecation")
			Notification notification = new Notification(R.drawable.icon,"stringa",when);
    	  	notification.setLatestEventInfo(aRef, title, text, pIntent);
    	  	notificationManager.notify(id, notification);
    	}*/
	}
}
